<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>


<%@ page import =  "java.util.HashMap,
                    org.apache.commons.beanutils.PropertyUtils,
                    org.apache.struts.validator.DynaValidatorForm"
%>



<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>




<script language="JavaScript">

  var isNav = (navigator.appName.indexOf("Netscape") != -1);
  var isIE = (navigator.appName.indexOf("Microsoft") != -1);

  function findField(theForm, fieldName) {
    var elements = theForm.elements;
    var numElements = elements.length;
    for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
      var elementName = elements[elementIndex].name;
      if (elementName == fieldName) {
        return elements[elementIndex];
      }
    }
    return null;
  }

  function gotoFirstPage(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      thisForm.currentPageNumber.value = 1;
      thisForm.submit();
      return false;
    }
  }


function doGroupViewAction(theForm, i) {
    var fieldName = 'oneGroup[' + i + '].fqn';
    var field = findField(theForm, fieldName);
    theForm.groupFQN.value=field.value;
    theForm.action = '<html-el:rewrite page="/mt/groupView.do" />';
    theForm.method = "post";
    theForm.submit();
    return true;
  }

function doGroupEditAction(theForm, i) {
    var fieldName = 'oneGroup[' + i + '].fqn';
    var field = findField(theForm, fieldName);
    //theForm.parentGroupFQN.value=theForm.groupFQN.value;
    theForm.groupFQN.value=field.value;
    theForm.action = '<html-el:rewrite page="/mt/groupEdit.do" />';
    theForm.submit();
    return true;
  }

  function gotoPreviousPage(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      var currentPageNumber = thisForm.currentPageNumber.value;
      currentPageNumber--;
      if (thisForm.entriesPerPage.value != <c:out value="${mtGroupSearchForm.map.entriesPerPage}"/>) {
        currentPageNumber = 1;
      }
      if (currentPageNumber > 0) {
        thisForm.currentPageNumber.value = currentPageNumber;
        thisForm.submit();
      }
    }
  }

  function gotoNextPage(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      var currentPageNumber = thisForm.currentPageNumber.value;
      currentPageNumber++;
      if (thisForm.entriesPerPage.value != <c:out value="${mtGroupSearchForm.map.entriesPerPage}"/>) {
        currentPageNumber = 1;
      }
      if (currentPageNumber <= thisForm.totalPageNumber.value) {
        thisForm.currentPageNumber.value = currentPageNumber;
        thisForm.submit();
      }
    }
  }

  function gotoLastPage(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage.value != <c:out value="${mtGroupSearchForm.map.entriesPerPage}"/>) {
        thisForm.currentPageNumber.value = 1;
      }
      else {
        thisForm.currentPageNumber.value = thisForm.totalPageNumber.value;
      }
      thisForm.submit();
    }
  }


  function doGo(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage.value != <c:out value="${mtGroupSearchForm.map.entriesPerPage}"/>) {
        thisForm.currentPageNumber.value = 1;
        return true;
      }
    }
    return false;
  }


	          function onClickGroupBrowseTab() {
	   	   	  var  theForm=document.forms['mtGroupSearchForm'];
	   	             theForm.action = '<html-el:rewrite page="/mt/groupView.do" />';
	   	     	      theForm.submit();
	   	         return false;
	   	       }


	   	    function onClickGroupSearchTab() {
	   	   	  			var  theForm=document.forms['mtGroupSearchForm'];
	   	   	  			   theForm.doSearch.value="false";
	   	           	   theForm.action = '<html-el:rewrite page="/mt/groupSearch.do" />';
	   	   	    	   theForm.submit();
	   	         return false;
	     }
</script>

<%
  java.util.HashMap map = new java.util.HashMap();
  DynaValidatorForm mtGroupSearchForm = (DynaValidatorForm) request.getAttribute("mtGroupSearchForm");
   map.put("groupFQN", (String) PropertyUtils.getSimpleProperty(mtGroupSearchForm, "groupFQN"));
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>


<c:set var="editImg">
<img src="<%= request.getContextPath() %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="mt.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="mt.messages"/>">
</c:set>

<html-el:form action="/mt/groupSearch.do">

<html-el:hidden property="groupFQN"/>

<html-el:hidden property="currentPageNumber"/>
<html-el:hidden property="totalPageNumber"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">

      <div class="pageTitle">
        <bean-el:message key="mt.group.search.title" bundle="mt.messages"/>
      </div>

      <div class="errorMessage"><html-el:errors bundle="mt.messages"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>

      <!-- end of PageTab -->

      <div class="pageSubtitle">
        <span class="left">
          <bean-el:message key="mt.group.search.criteria" bundle="mt.messages"/>
        </span>
        <span class="right">
	  &nbsp;
        </span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Process summary">
        <tr>
          <td class="label" width="30%">
            <bean-el:message key="mt.group.search.label.lookin" bundle="mt.messages"/>:
          </td>
          <td class="labelField" width="70%" colspan="2">
              <html-el:radio name="mtGroupSearchForm" property="searchAllGroups" value="1"/>
              <bean-el:message key="mt.group.search.label.allGroups" bundle="mt.messages"/>
              <br>
              <html-el:radio name="mtGroupSearchForm" property="searchAllGroups" value="0"/>
                <bean-el:message key="mt.group.search.label.currentGroup" bundle="mt.messages" />: &nbsp;
                <i><c:out value="${mtGroupSearchView.map.groupName}"/></i>
            </td>
        </tr>

        <tr>
          <td class=label width="30%">
            <bean-el:message key="mt.group.search.label.name" bundle="mt.messages"/>:
          </td>
          <td class=labelField vAlign=top width="70%" colspan="2">
            <html-el:text  name="mtGroupSearchForm" property="searchStr"/>
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
            <bean-el:message key="mt.group.search.label.maxNumberToFind" bundle="mt.messages"/>:
          </td>
          <td class="labelField" width="70%" colspan="2">
            <html-el:text property="maxNumberToFind"/>
          </td>
	</tr>
	<tr>
          <td class="label" width="30%">
            <bean-el:message key="mt.group.search.label.rowsPerPage" bundle="mt.messages"/>:
          </td>
	  <td class="labelField" width="70%" colspan="2">
            <html-el:select property="entriesPerPage" size="1">
              <html-el:option value="10">10</html-el:option>
              <html-el:option value="20">20</html-el:option>
              <html-el:option value="30">30</html-el:option>
              <html-el:option value="50">50</html-el:option>
              <html-el:option value="100">100</html-el:option>
            </html-el:select>
	  </td>
        </tr>
      </table> <!-- end of Header Info table -->

      <div class="pageButtonWrap" align="right">
          <input hspace="40" type="submit" name="btn_action" class="pageButton" value="<bean-el:message key="button.showResults" bundle="mt.messages"/>" onclick="javascript:return gotoFirstPage('mtGroupSearchForm');">
      </div>
      <br>

      <!--start main content area here-->
      <c:if test="${mtGroupSearchForm.map.doSearch == 'true'}">

           <div class="pageSubtitle">
              <span class="left">
                <bean-el:message key="mt.group.groups"  bundle="mt.messages" />
              </span>
              <span class="right">
              </span>
            </div>

            <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Category" width="100%">
             <tr class="listHeader">
               <th id="SubCategoryName" align="left" width="40%">
                 <bean-el:message key="mt.group.label.groupName" bundle="mt.messages"/>
               </th>
               <th id="Actions" align="left"  width="15%" nowrap>
                 <bean-el:message key="mt.header.actions" bundle="mt.messages"/>
               </th>
             </tr>

             <c:choose>
               <c:when test="${not empty mtGroupSearchView.map.groupList}">
                 <c:forEach var="oneGroup" items="${mtGroupSearchView.map.groupList}" varStatus="status">
                   <html-el:hidden name="oneGroup" property="fqn" indexed="true"/>
                   <c:choose>
                     <c:when test="${(status.count + 1) % 2 == 0}">
	     <tr class="listEven">
                     </c:when>
                     <c:otherwise>
             <tr class="listOdd">
	             </c:otherwise>
                   </c:choose>

               <td headers="SubCategoryName" align="left" width="40%">
                 <c:url var="viewUrl" value="/mt/groupView.do">
                   <c:param name="groupFQN" value="${oneGroup.map.fqn}"/>
                 </c:url>
                 <a href='#' onclick="JavaScript:doGroupViewAction(document.mtGroupSearchForm, <c:out value="${status.count - 1}"/>);">
		                <c:out value="${oneGroup.map.name}"/></a>
                 &nbsp;
               </td>
               <td nowrap align="left" headers="Actions">
                 <c:url var="viewUrl" value="/mt/groupEdit.do">
                   <c:param name="groupFQN" value="${oneGroup.map.fqn}"/>
                 </c:url>

                <a href='#' onclick="JavaScript:doGroupEditAction(document.mtGroupSearchForm, <c:out value="${status.count - 1}"/>);">
                   <c:out value='${editImg}' escapeXml="false"/></a>
               </td>
             </tr>

               </c:forEach>
             </c:when>

             <c:otherwise>
               <tr class="listOdd">
                 <td colspan=7 align="center">
                   <bean-el:message key="mt.group.noGroup" bundle="mt.messages"/>
                 </td>
               </tr>
             </c:otherwise>
           </c:choose>
          </table>

        <!--end main content area here-->

      <c:if test="${mtGroupSearchView.map.numOfGroups > 0 || mtGroupSearchView.map.numOfUsers > 0}">
        <div class="pagination">

          <c:if test="${mtGroupSearchForm.map.totalPageNumber > 1}">
            &nbsp;&nbsp;&nbsp;
            <c:if test="${mtGroupSearchForm.map.currentPageNumber > 0}">
              <c:if test="${mtGroupSearchForm.map.totalPageNumber > 1}">
                <c:if test="${mtGroupSearchForm.map.currentPageNumber > 1}">
                  <a href="#" class="paginationBtn" onclick="javascript:gotoFirstPage('mtGroupSearchForm')">
                    <bean-el:message key="page.first" bundle="mt.messages"/></a>
                  <a href="#" class="paginationBtn" onclick="javascript:gotoPreviousPage('mtGroupSearchForm')">
                    <bean-el:message key="page.previous" bundle="mt.messages"/></a>
                </c:if>
              </c:if>
              <c:set var="currentPageNumberAttr" scope="page" value="${mtGroupSearchForm.map.currentPageNumber}"/>
              <c:set var="totalPageNumberAttr" scope="page" value="${mtGroupSearchForm.map.totalPageNumber}"/>
              <% Integer currentPageNumberInt = (Integer)pageContext.getAttribute("currentPageNumberAttr"); %>
              <% Integer totalPageNumberInt = (Integer)pageContext.getAttribute("totalPageNumberAttr"); %>
              <bean-el:message key="page.pageOf"
                arg0="<%= currentPageNumberInt.toString() %>"
                arg1="<%= totalPageNumberInt.toString() %>"   bundle="mt.messages"/>
              <c:if test="${mtGroupSearchForm.map.totalPageNumber > 1}">
                <c:if test="${mtGroupSearchForm.map.currentPageNumber < mtGroupSearchForm.map.totalPageNumber}">
                  <a href="#" class="paginationBtn" onclick="javascript:gotoNextPage('mtGroupSearchForm')">
                    <bean-el:message key="page.next"  bundle="mt.messages"/></a>
                  <a href="#" class="paginationBtn" onclick="javascript:gotoLastPage('mtGroupSearchForm')">
                    <bean-el:message key="page.last" bundle="mt.messages"/></a>
                </c:if>
              </c:if>
            </c:if>
          </c:if>
        </div>
      </c:if>

  </c:if>
    </td>
  </tr>
</table>

<html-el:hidden property="doSearch" value="true"/>

</html-el:form>


